package cn.mzcode.xyzpfuwuduan.service.impl;

import cn.mzcode.xyzpfuwuduan.common.ServerResponse;
import cn.mzcode.xyzpfuwuduan.dao.CompanyMapper;
import cn.mzcode.xyzpfuwuduan.dao.PositionMapper;
import cn.mzcode.xyzpfuwuduan.pojo.Position;
import cn.mzcode.xyzpfuwuduan.service.IPositionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PositionSerivceImpl implements IPositionService {

    @Autowired
    private PositionMapper positionMapper;

    @Override
    public void selectByPrimaryKey(Integer positionId) {

    }

    @Override
    public ServerResponse saveOrUpdatePosition(Position position) {
       if (position!=null){
           if (position.getId()!=null){
               int rowCount=positionMapper.updateByPrimaryKey(position);
               if (rowCount>0){
                   return ServerResponse.createBySuccess("更新职位成功");
               }
               return ServerResponse.createByErrorMessage("更新职位失败");
           }else {
               int rowCount=positionMapper.insert(position);
               if (rowCount>0){
                   return ServerResponse.createBySuccess("添加职位成功");
               }
               return ServerResponse.createByErrorMessage("添加职位失败");
           }
       }
       return ServerResponse.createByErrorMessage("新增或更新职位参数错误");
    }

    @Override
    public ServerResponse<PageInfo> selectPosition(Position position, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);

        List<Position> positionList=positionMapper.selectBySelective(position);
        PageInfo<Position> pageInfo=new PageInfo<>(positionList);

        //todo

        return ServerResponse.createBySuccess(pageInfo);
    }
}
